﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Weight.Dal.Dispatch;
using Weight.Model;
using Weight.Model.ParamEntity;
using Weight.Model.ResultEntity;

namespace Weight.Bll.Dispatch
{
    public  class BllDispatch
    {
       private  DalDispatch dal = new DalDispatch();

        /// <summary>
        /// 列表
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public DispatchQueryRes List(QueryDispatchReq req)
        {
            return dal.List(req);
        }

        /// <summary>
        /// 查询派车数据
        /// </summary>
        /// <param name="filterVal"></param>
        /// <returns></returns>
        public IEnumerable<DispatchCarEntity> Query(string filterVal)
        {
            return dal.Query(filterVal);
        }

        /// <summary>
        /// 选择列表
        /// </summary>
        /// <param name="plateNum"></param>
        /// <param name="customer"></param>
        /// <param name="material"></param>
        /// <returns></returns>
        public IEnumerable<DispatchCarEntity> ListSelect(string plateNum, string customer, string material)
        {
            return dal.ListSelect(plateNum,customer,material);
        }

        /// <summary>
        /// 根据Id获取派车
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Tuple<bool, string, DispatchCarEntity> GetById(string id)
        {
            if(string.IsNullOrEmpty(id))
            {
                return new Tuple<bool,string, DispatchCarEntity>(false,"参数错误",null);
            }
            else
            {
                var data = dal.GetById(id);
                return new Tuple<bool, string, DispatchCarEntity>(true,"",data);
            }
        }

        /// <summary>
        /// 根据车号获取派车信息
        /// </summary>
        /// <param name="plateNum"></param>
        /// <returns></returns>
        public Tuple<bool, string, DispatchCarEntity> GetByPlateNum(string plateNum)
        {
            if (string.IsNullOrEmpty(plateNum))
            {
                return new Tuple<bool, string, DispatchCarEntity>(false, "参数错误", null);
            }
            else
            {
                var data = dal.GetByPlateNum(plateNum);
                return new Tuple<bool, string, DispatchCarEntity>(true, "", data);
            }
        }


        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public Tuple<bool,string> Update(DispatchCarEntity entity)
        {
            if(entity == null)
            {
                return new Tuple<bool, string>(false,"参数错误");
            }
            if(dal.Update(entity))
            {
                return new Tuple<bool, string>(true,"修改成功");
            }
            else
            {
                return new Tuple<bool, string>(false,"修改失败");
            }
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public Tuple<bool,string> Insert(DispatchCarEntity entity)
        {
            if(entity == null)
            {
                return new Tuple<bool, string>(false,"参数错误");
            }
            else
            {
                if(dal.Insert(entity))
                {
                    return new Tuple<bool, string>(true,"保存成功");
                }
                else
                {
                    return new Tuple<bool, string>(false, "保存失败");
                }
            }
        }

        /// <summary>
        /// 判断是否存在
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool IsExist(string id)
        {
            return dal.IsExist(id);
        }

        /// <summary>
        /// 删除操作
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool delete(string id)
        {
            return dal.delete(id);
        }
    }


}
